package com.chuan.jms.cosumer;

import org.springframework.beans.factory.annotation.Autowired;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import java.util.concurrent.*;

/**
 * Created by zhaowenchuan on 2018/10/25.
 */
public class ConsumerContainerListener implements MessageListener {

    @Autowired
    private GenerateThreadPool generateThreadPool;

    private ExecutorService executorService = generateThreadPool.generatePool();

    @Override
    public void onMessage(Message message) {
        final TextMessage textMessage = (TextMessage) message;
        try {
            executorService.execute(new ConsumerThread(textMessage.getText()));
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
